<?php
namespace plugin\luyouzujiditu\admin;

use plugin\luyouzujiditu\model\PluginLuyouzujidituTop as models ;
use plugin\luyouzujiditu\validate\TopValidate as validates ;
use app\admin\common\Baseadmin;

use think\facade\Db;

class Top extends Baseadmin
{
    public function lists()
    {
        $request= (new validates())->IsCheck('lists');
        $field="";
        $map   =[];

        $map[] = ["status", "=", 2 ];
        //map =排序   field = 空则全部输出 order排序  page 每页条数
        $model =(new models())->paginate($map, $field, $order='id desc', $page=20);
        $data['list']=$model;
        ajaxmsg('ok', 200, $data);
    }

 

    public function views()
    {
        $request= (new validates())->IsCheck();
        $field='';
        $map   =[];
        $map[] = ["id", "=", input('request.id') ];
        $model =(new models())->finds($map, $field);
        $data['find']=$model;
        if ($model) {
            ajaxmsg('成功', 200, $data);
        }
        ajaxmsg('内容不存在', 0);
    }
    public function edit()
    {
        $request= (new validates())->IsCheck('edit');
        $field='';
        $map   =[];
        $map[] = ["id", "=", input('request.id') ];
        $request["status"]= 2;
        $request["userip"]= request()->ip();
        ;
 
        if (input('request.id') > 0) {
            //编辑
            //$field=["open",'name']; 示例
            // $map[] = ['name', 'like', "%".input('request.name')."%" ]; 搜索示例
            // $map[] = ['id', '=', input('request.select')]; 普通示例
            $model =(new models())->updates($map, $request, $field);
        } else {
            //新增
            $model =(new models())->adds($request, $field);
        }
        if ($model) {
            ajaxmsg('成功', 200);
        }
        ajaxmsg('失败', 0);
    }
       
       
    public function dels()
    {
        $request= (new validates())->IsCheck();
              
        (new models())->where('id', $request['id'])->delete();
        ajaxmsg('成功', 200);
    }
       
 
    //控制器方法
}
